//

#ifndef _BASE_HPP
#define _BASE_HPP

#include <wtk/wtk.hpp>



typedef int PipelineID;
typedef int RenderModeID;
typedef int EntityGroupID;



// [FIXME]
inline constexpr size_t MAX_LIGHTS = 4;



// EntityGroup
//
enum EntityGroup
  {
    ENTITY_MARKER,
    ENTITY_OBJECT,
    ENTITY_LIGHT_SOURCE,
  };



// get_gl_type_name
//
inline std::string get_gl_type_name ( GLenum type )
{
  switch (type)
    {
    case GL_BOOL:       return "bool";
    case GL_FLOAT:      return "float";
    case GL_FLOAT_VEC2: return "vec2";
    case GL_FLOAT_VEC3: return "vec3";
    case GL_FLOAT_VEC4: return "vec4";
    case GL_FLOAT_MAT2: return "mat2";
    case GL_FLOAT_MAT3: return "mat3";
    case GL_FLOAT_MAT4: return "mat4";
    case GL_SAMPLER_2D: return "sampler2D";
    default: return "unknown (" + std::to_string(type) + ")";
    }
}



// [FIXME] logging
#include <stdio.h>

#define GLT_LOG(f, lvl, msg...) do {            \
    fprintf((f), "gltest:%s:%d:%s ",            \
            __FILE__, __LINE__, (lvl));         \
    fprintf((f), msg);                          \
    fprintf((f), "\n");                         \
  } while (0)

#define GLT_TRACE(msg...) GLT_LOG(stdout, "", msg)

#define GLT_WARNING(msg...) GLT_LOG(stderr, "WARNING:", msg)

#define GLT_ERROR(msg...) GLT_LOG(stderr, "ERROR:", msg)

#define GLT_FATAL(msg...) do {                  \
    GLT_ERROR(msg);                             \
    abort();                                    \
  } while (0)

#define GLT_ASSERT(expr) do {                       \
    if (!(expr)) {                                  \
      GLT_FATAL("ASSERTION FAILED: `" #expr "'");   \
    }                                               \
  } while (0)



#endif
